home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / gle.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  8KB  |  265 lines

  1. #include "all.h"
  2. #include <math.h>
  3. #ifdef __TURBOC__
  4. #include "conio.h"
  5. #include "bios.h"
  6. #endif
  7. #if ( defined DJ || defined EMXOS2 )      /* a.r. */
  8.         #define unix
  9. #endif
  10. #ifdef EMXOS2
  11.         int flagSURFOS2 = 0;
  12.         FILE *ErrFileSURFOS2;
  13.         int pmFlag;
  14.         extern unsigned long stopPMSession(unsigned long SessID);
  15.         extern unsigned long oldSession;
  16. #endif
  17.  
  18. int gle_debug;
  19. int dev_eps=0;
  20. int control_d = !0;
  21. int MAX_VECTOR=500;
  22. int dev_fill,dev_font; /* do real filling for d_dvi.c, and use texcmr font */
  23. extern int trace_on;
  24. int init_memory(void);
  25. int text_expand(int n);
  26. int g_get_type(char *s);
  27. int gle_redraw(void);
  28. int scr_init(void);
  29. int scr_end(void);
  30. #define true (!false)
  31. #define false 0
  32. int noscreenio=true;
  33. int BLACKANDWHITE=(false);
  34. #define dbg if (gle_debug>0)
  35. #ifdef __TURBOC__
  36.         extern unsigned _stklen=45000;
  37. #endif
  38.  
  39. typedef char (*TEXT)[];
  40. int int_edt(char *fname);
  41. int scrinsert(int y);
  42. int scrdeleteline(int y);
  43. int text_eol(void);
  44. int text_delete(void);
  45. int text_undelete(void);
  46. int text_deleteline(void);
  47. int text_left(void);
  48. int text_right(void);
  49. int text_up(void);
  50. int text_down(void);
  51. int text_return(void);
  52. int text_refresh();
  53. int text_putstr(char *s);
  54. int text_setwindow();
  55. int text_move(int x,int y);
  56. int scr_tab(char *s, int x);
  57. int scr_negtab(char *s, int x, int *fpos, int *scrx);
  58. int fner(char *s);
  59. int fner_clear(void);
  60. int text_setwindow(void);
  61. int text_refresh(void);
  62. int text_main(void);
  63. int text_inkey(void);
  64. int text_scroll(void);
  65. int text_scroll_up(void);
  66. int text_scroll_down(void);
  67. int text_select(void);
  68. int text_cut(void);
  69. int text_paste(void);
  70. int restofline(int y,int x);
  71. int normal_key(int c);
  72. int setoutfile(char *s);
  73. int lineset(int i,char *ss);
  74. int lineinsert(int y, char *ss);
  75. int textinsert(int y);
  76. char *sline(int i);
  77. int text_load(char *f);
  78. int print_out(void);
  79. char *line(int i);
  80. int ncpy(char *d, char *s, int n);
  81. /*------------ GLOBAL VARIABLES --------------*/
  82. char input_file[50];
  83. char *(*gtxt)[];   /* gtxt is a pointer to an array of poiter to char */
  84. int ngtxt=0;
  85. char gleroot[60];
  86. char glearg0[66];
  87. int gotfile;
  88. int hpgl_size;
  89.  
  90.  
  91. /*---------------------------------------------------------------------------*/
  92. #ifdef unix
  93. #include "glepath.h"
  94. #endif
  95. main(int argc, char **argv)
  96. {
  97. char dtype[60];
  98. char fname[60],*ss;
  99. static int i,ask_debug,spawn_print,call_menu,drawit;
  100.         strcpy(fname,"test.gle");
  101.         strcpy(glearg0,argv[0]);
  102.         strcpy(gleroot,argv[0]);
  103.         init_memory(); /* saves some memory for emergencies */
  104. #ifdef VMS
  105.         if (strcmp(strupr(getsymbol("GLE_NOCONTROLD")),"TRUE")==0) {
  106.                 control_d = false;
  107.         }
  108. #endif
  109. #ifdef unix
  110.         dtype[0] = 0;
  111.         ss = getenv("GLE_TOP");
  112.         if (ss==NULL) ss = GLEPATH;
  113.         strcpy(gleroot,ss);
  114.         control_d = false;
  115. #endif
  116. #ifdef __TURBOC__
  117.         ss = strchr(gleroot,'\\');
  118.         if (ss==NULL) gle_abort("Unable to locate files AGRV[0] wrong");
  119.         for (;strchr(ss+1,'\\')!=NULL;) ss = strchr(ss+1,'\\');
  120.         *(ss+1) = 0;
  121.         if (getenv("GLE_NOCONTROLD")!=NULL) control_d = false;
  122. #endif
  123. #ifdef VAXC
  124.         if (strcmp(getsymbol("GLE_NOCONTROLD"),"TRUE")==0) control_d = false;
  125. #endif
  126.         hpgl_size = 3;
  127.         for (i=1;i<argc;i++) {
  128.                 strcpy(dtype,argv[i]);
  129.                 strupr( argv[i] );
  130.                 if (strcmp( argv[i] , "/TRACE")==0) trace_on = true;
  131.                 else if (strcmp( argv[i] , "/DEBUG")==0) ask_debug = true;
  132.                 else if (strcmp( argv[i] , "/PRINT")==0) spawn_print = true;
  133.                 else if (strncmp( argv[i] , "/DEV", 4)==0) spawn_print = false;
  134.                 else if (strcmp( argv[i] , "/NOD")==0) control_d = false;
  135.                 else if (strcmp( argv[i] , "/ADDD")==0) control_d = true;
  136.                 else if (strcmp( argv[i] , "/A0")==0) hpgl_size = 0;
  137.                 else if (strcmp( argv[i] , "/A1")==0) hpgl_size = 1;
  138.                 else if (strcmp( argv[i] , "/A2")==0) hpgl_size = 2;
  139.                 else if (strcmp( argv[i] , "/A3")==0) hpgl_size = 3;
  140.                 else if (strcmp( argv[i] , "/A4")==0) hpgl_size = 4;
  141.                 else if (strcmp( argv[i] , "/MENU")==0) call_menu = true;
  142.                 else if (strcmp( argv[i] , "/EPS")==0) dev_eps = true;
  143.                 else if (strcmp( argv[i] , "/FILL")==0) dev_fill = true;
  144.                 else if (strcmp( argv[i] , "/FONT")==0) dev_font = true;
  145.                 else if (strcmp( argv[i] , "/NOMAXPATH")==0) MAX_VECTOR = 999999;
  146.                 else if (strcmp( argv[i] , "/COLOR")==0) BLACKANDWHITE = false;
  147.                 else if (strcmp( argv[i] , "/NOCOLOR")==0) BLACKANDWHITE = false;
  148.                 else if (strncmp( argv[i] , "/OUT", 4)==0) setoutfile(argv[i]);
  149.                 else if (strncmp( argv[i] , "/DRA", 4)==0) drawit = true;
  150.                 else if (!gotfile && (isalnum(*argv[i]) || (*argv[i] == '['))) {strcpy(fname, dtype); gotfile=true;}
  151.                 else printf("Unrecognised qualifier {%s} \n",argv[i]);
  152.         }
  153. /*        if (argc>1) strcpy(fname,*(++argv)); else strcpy(fname,"test.gle");*/
  154.         g_get_type(dtype);
  155.         /* works here */
  156.         
  157. #ifdef EMXOS2 /* a.r. - prevent locking PM single Message Queue */
  158.         if (strstr(dtype, "OS2PM")!=NULL && drawit == true)
  159.                {
  160.                 pmFlag = 1;
  161.                 if (!gotfile) exit(1);
  162.                }
  163.         else
  164.                 pmFlag = 0;
  165. #endif
  166.  
  167.         if (strstr(dtype,"HARDCOPY")!=NULL  && !call_menu) {
  168.                 if (!gotfile) {
  169. try_again:                gprint("Enter name of GLE file ? ");
  170.                         gets(fname);
  171.                         ss = strchr(fname,'\n');
  172.                         if (ss!=NULL) *ss = 0;
  173.                         if (strcmp(fname,"")==0) goto try_again;
  174.                 }
  175.         }
  176.  
  177.         if (strchr(fname,'.')==NULL) strcat(fname,".gle");
  178. /* works*/
  179.         if (strstr(dtype,"HARDCOPY")==NULL  || call_menu) {
  180.                 noscreenio = false;
  181.                 scr_init();
  182.         }
  183.         strcpy(input_file,fname);
  184.         text_expand(500); /* Initially allocate 500 lines of text */
  185.  
  186.         if (strstr(dtype,"HARDCOPY")!=NULL  && !call_menu) {
  187.                 text_load(fname);
  188.                 if (ask_debug) {
  189.                 printf("Debug options 16=do_pcode, 8=pass 4=polish, 2=eval ");
  190.                 printf("Debug ");scanf("%d",&gle_debug);
  191.                 printf("Trace "); scanf("%d",&trace_on);
  192.                 }
  193.                 gle_redraw();
  194.         } else {
  195.                 noscreenio = false;
  196.                 if (coreleft()<120000L) {
  197.  printf("\n\nThere is not enough memory for GLE to run properly, follow these guidelines\n");
  198.  printf("to free up more memory.\n");
  199.  printf("        1) Don't run GLE from inside editors/file utilities.\n");
  200.  printf("        2) Don't run GLE at the same time as disk servers like:\n");
  201.  printf("                NOVELL, PCSA, VDISK, RAF etc...\n");
  202.  printf("        3) Remove any extra's from CONFIG.SYS and AUTOEXEC.BAT\n");
  203.  printf("                (after taking copies of them)\n\n");
  204.  printf("        (GLE will attempt to continue by not using any complex fonts)\n");
  205.  printf("Press any key to continue");
  206.                         font_simple();
  207.                         if (!drawit) text_inkey();
  208.                 }
  209.                 if (gotfile) text_load(fname);
  210.                 if (drawit) gle_redraw();
  211.                 else int_edt(fname);
  212.         }
  213.         if (!noscreenio) scr_end();
  214. /*         if (spawn_print) {
  215.                 print_out();
  216.         } */
  217.  
  218.  
  219. #ifdef EMXOS2                                           /* a.r. */
  220.         stopPMSession(oldSession);
  221.         unlink("GLEOS2.TMP");
  222.         if (drawit != true)
  223.                 unlink("GLEOS2.ERR");
  224. #endif
  225. #ifdef VMS
  226.         return 1;
  227. #else
  228.         return 0;
  229. #endif
  230. }
  231. #ifdef unix
  232. print_out(){}
  233. #endif
  234. #ifdef __TURBOC__
  235. print_out()
  236. {}
  237. #else
  238. #ifdef VMS
  239. #include <descrip.h>
  240. /* #include <lib$routines.h> */
  241. print_out()
  242. {
  243.         static $DESCRIPTOR(cmd_desc
  244.           ,"print out.ps /que=laser/notify/noburst/noflag");
  245.  
  246.         printf("$ %s \n",cmd_desc.dsc$a_pointer);
  247.         LIB$DO_COMMAND(&cmd_desc);
  248. }
  249. #endif
  250. #endif
  251. char output_file[80];
  252. setoutfile(char *q)
  253. {
  254.         char *s;
  255.         s = strchr(q,'=');
  256.         if (s==NULL) return;
  257.         strcpy(output_file,s+1);
  258.         strlwr(output_file);
  259. }
  260.  
  261.  
  262.  
  263.  
  264.  
  265.